home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12375 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.4 KB

  1. Path: news1.intercall.com!usenet
  2. From: engevar@intercall.com (Steven Ovits)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: modularity and data hiding
  5. Date: Sat, 30 Mar 1996 23:15:09 GMT
  6. Organization: Intercall Inc.
  7. Message-ID: <4jk5mm$9s0@news1.intercall.com>
  8. References: <4jjvl9$phl@news.bu.edu>
  9. NNTP-Posting-Host: ts2-111.intercall.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. lachesis@bu.edu (wai yip) wrote:
  13.  
  14. >hmmm, i seem to be posting here everytime i get a new homework
  15. >assignment...don't know if it's a good thing.  anyway, i seem to have a
  16.  
  17. No, it's probably not a good thing. Better to talk things out with
  18. your classmates.
  19.  
  20. >problem understanding data hiding.  i have an assignment which requires me to
  21. >store 3 letter airport codes in a binary search tree.
  22. >i have to do it using modularity and data hiding with 5 files(a main file,
  23. >interface.c file, implementation.c file, interface.h file and an
  24. >implementation.h file).
  25.  
  26. >what i don't understand is why i need so many files.  in the book i read, they
  27. >only discussed the necessity for an interface.h file which stores declarations
  28. >and definitions for prototypes and the implementation.c file which has all the
  29. >functions for accessing the tree.
  30.  
  31. You probably wouldn't need so many files in a small project in the
  32. real world. On the other hand, you do need to know how to use
  33. several files, so they're teaching you how on a small project.
  34.  
  35. >so why do i need a .c and .h file for both the implementation and interface
  36. >files?  am i missing some important point in data hiding?
  37. >hope i don't sound too stupid posting these types of questions ^_^
  38. >any help would be appreciated.
  39.  
  40. Let's say you are writing a huge program. You put the binary tree
  41. code in one souirce (bt.c) file and use the header file (bt.h) to
  42. access the functions (add, remove, next) by including the header
  43. (bt.h) in the other source file. One advantage is that you could
  44. reuse the binary tree code in another program. Another is that
  45. you may have a dozen of these things in a large program, and it's
  46. much easier to manage if the code is in separate modules.
  47.  
  48. Other modules might be used for i/o, for airport-specific functions,
  49. and for the main program. You might move the program to another
  50. operating system, and if you're lucky, you could reuse the binary-
  51. tree and airport code, and even the main program--you'd just have
  52. to replace the i/o part.
  53.  
  54. There's more to this, but I'll let one of the language experts
  55. handle those parts.
  56.  
  57.